﻿using BSChuangXu.API.Read.Appicant.Commend.RoleMenuCommand;
using BSChuangXu.Domain.User;
using BSChuangXu.ErrorCode;
using BSChuangXu.Infrastructure.Interface;
using MediatR;

namespace BSChuangXu.API.Read.Appicant.CommendHandel.RoleMenuCommandHandler
{
    /// <summary>
    /// 反填获取菜单命令执行
    /// </summary>
    public class GetFanTianCommandHandler : IRequestHandler<GetFanTianCommand, APIResult<List<RoleMenu>>>
    {
        private readonly IBaseRepository<RoleMenu> roleMenuRepos;

        public GetFanTianCommandHandler(IBaseRepository<RoleMenu> roleMenuRepos)
        {
            this.roleMenuRepos = roleMenuRepos;
        }
        /// <summary>
        /// 反填获取菜单(名称,id)
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<List<RoleMenu>>> Handle(GetFanTianCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<RoleMenu>> result = new APIResult<List<RoleMenu>>();

            var list = roleMenuRepos.GetAll().Result.Where(x => x.RoleId == request.RoleId);
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.data = list.ToList();
            return await Task.FromResult(result);
        }
    }
}
